//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.anolesoft.twelveFactory.planManagement.controller;

import com.anolesoft.common.core.domain.LoginUser;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.system.fac.entity.Employee;
import com.anolesoft.system.fac.service.IEmployeeService;
import com.anolesoft.twelveFactory.planManagement.entity.ProcessingHistory;
import com.anolesoft.twelveFactory.planManagement.service.ProcessingHistoryService;
import com.anolesoft.yr.demo.PageResult;
import com.anolesoft.yr.util.Constants;
import com.anolesoft.yr.util.HttpStatus;
import com.anolesoft.yr.util.PageData;
import com.anolesoft.yr.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.time.LocalDate;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping({"/twelveFactory/processingHistory"})
public class ProcessingHistoryController {
    @Autowired
    private ProcessingHistoryService processingHistoryService;
    @Autowired
    private IEmployeeService iEmployeeService;

    public ProcessingHistoryController() {
    }
//加工历史
    @PostMapping(
            value = {"/listProcessingHistory"},
            produces = {"application/json"}
    )
    public AjaxResult selectProcessingHistory(@RequestBody ProcessingHistory processingHistory) {
        PageData<List<ProcessingHistory>> pageData = this.processingHistoryService.listProcessingHistory(processingHistory);
        PageResult pageResult = new PageResult((List)pageData.getItems(), processingHistory.getPageSize(), processingHistory.getPageNo(), pageData.getTotal());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, pageResult);
    }

    @PostMapping({"/insert"})
    public AjaxResult insert(@RequestBody ProcessingHistory processingHistory) {
        processingHistory.setCjsj(Date.valueOf(LocalDate.now()));
        LoginUser login=SecurityUtils.getLoginUser();
        processingHistory.setCjr(SecurityUtils.getLoginUser().getUsername());
        Employee employee = (Employee)this.iEmployeeService.getById(SecurityUtils.getLoginUser().getEmpUid());
        if(employee!=null){
            if(employee.getFacCode()!=null){
                processingHistory.setCdh(employee.getFacCode());
            }
        }
        return new AjaxResult(HttpStatus.SUCCESS, Constants.CREATE_SUCCESS_MESSAGE, this.processingHistoryService.insert(processingHistory));
    }

    @PostMapping({"/update"})
    public AjaxResult update(@RequestBody ProcessingHistory processingHistory) {
        return new AjaxResult(HttpStatus.SUCCESS, Constants.MODIFY_SUCCESS_MESSAGE, this.processingHistoryService.update(processingHistory));
    }

    @GetMapping({"/delete"})
    public AjaxResult delete(String objuid) {
        return new AjaxResult(HttpStatus.SUCCESS, Constants.DELETE_SUCCESS_MESSAGE, this.processingHistoryService.delete(objuid));
    }

    @GetMapping({"/selectById"})
    public AjaxResult selectById(String objuid) {
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, this.processingHistoryService.selectById(objuid));
    }
}
